package com.neusoft.neumooc.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.neusoft.core.common.BaseDAO;
import com.neusoft.core.common.exception.DAOException;
import com.neusoft.neumooc.VO.GoodsKindVO;
import com.neusoft.neumooc.VO.GoodsVO;

@Repository
public class GoodsDaoImpl extends BaseDAO implements GoodsDao {

	/**
	 * @Fields QUERY_GOODS_KIND_COUNT : 商品分类总数
	 */
	private final static String QUERY_GOODS_KIND_COUNT = "select count(1) from goodkind";

	@Override
	public int queryGoodsKindCount() throws DAOException {
		return this.queryInteger(QUERY_GOODS_KIND_COUNT);
	}

	/**
	 * @Fields GET_GOODS_KIND : 查询商品分类列表
	 */
	private final static String GET_GOODS_KIND = "select id,name from goodkind";

	@Override
	public List<GoodsKindVO> getGoodsKind(int pageNo, int pageSize)
			throws DAOException {
		return this.getPageData(GET_GOODS_KIND, GoodsKindVO.class, pageNo,
				pageSize);
	}

	/**
	 * @Fields GET_GOODS_LIST : 查询商品列表
	 */
	private final static String GET_GOODS_LIST = "select id,name,price,oldPrice,image,detail,status from good where kindid=?";

	@Override
	public List<GoodsVO> getGoodsList(String kindId, int pageIndex, int pageSize)
			throws DAOException {
		Object[] args = { kindId };
		return this.getPageData(GET_GOODS_LIST, GoodsVO.class, pageIndex,
				pageSize, args);
	}

	/**
	 * @Fields GET_GOODS_COUNT : 商品总数
	 */
	private final static String GET_GOODS_COUNT = "select count(1) from good where kindid=?";

	@Override
	public int getGoodsCount(String kindId) throws DAOException {
		Object[] args = { kindId };
		return this.queryInteger(GET_GOODS_COUNT, args);
	}
}
